package com.tm.commonutils.utils;


import com.tm.commonutils.enums.ResultCode;
import lombok.Data;

public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    public R() {
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public R(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getDesc();
        this.data = data;
    }
    public R(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getDesc();
    }


    public static R success(Object data){
        return new R(ResultCode.SUCCESS,data);
    }
    public static R success(){
        return success(null);
    }
    public static R fail(){
        return new R(ResultCode.ERROR);
    }
    public static R fail(ResultCode resultCode){
        return new R(resultCode);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
